package com.zhangdi.zddemo.thread;

import org.springframework.stereotype.Component;

@Component
public class BImpl implements TestB {
    private volatile static boolean off = false;
    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName() + off);
        while (true){
            if(Thread.currentThread().isInterrupted()){
                System.out.println("stop b");
                break;
            }
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                System.out.println("stop b exception");
                break;
            }
            System.out.println("bbb");
        }
    }

    @Override
    public void stop() {
        this.off = true;
        Thread.currentThread().getName();
        Thread.currentThread().interrupt();
    }
}
